package com.ww.learn.channel

import kotlinx.coroutines.*
import kotlinx.coroutines.channels.ReceiveChannel
import kotlinx.coroutines.channels.produce

@OptIn(ExperimentalCoroutinesApi::class)
fun main() = runBlocking {
    val producer: ReceiveChannel<Int> = produce(Dispatchers.IO) {
        for (i in 1..5) {
            com.ww.learn.coroutine.delay(100)
            send(i)
            println("生产: $i")
        }
    }

    launch(Dispatchers.Default) {
        for (data in producer) {
            println("消费：$data")
        }
    }.join()
}